{% extends "base.html" %}

{% block html_title %}
{% endblock html_title %}

{% block content %}
<div id="content">
    <el-dialog :visible.sync="formVisible" title="登陆"
               :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
        <el-form v-loading="formBlocking" element-loading-text="Checking URL &hellip;"
                 element-loading-spinner="el-icon-loading">
            <el-form-item label="用户名">
                <el-input v-model="username" placeholder="请输入您的用户名" clearable>
                    <!--<template slot="prepend">https://www.instagram.com/</template>-->
                </el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="password" placeholder="请输入您的密码" clearable>
                    <!--<template slot="prepend">https://www.instagram.com/</template>-->
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="login">登陆</el-button>
{#                <el-button>Cancel</el-button>#}
            </el-form-item>
        </el-form>
    </el-dialog>
</div>
{% endblock content %}

{% block js %}
<script>
    var container = new Vue({
        el: "#content",
        data: function() {
            return {
                formVisible: true,
                formBlocking: false,
                username: '',
                password: '',
            }
        },
        methods: {
            login: function() {
                this.$http.post("{{ url_for('auth.login') }}", {
                    username: this.username,
                    password: this.password
                }).then((res) => {
                    this.$notify({
                        title: "登陆成功",
                        message: "欢迎进入游戏统计后台",
                        type: "success"
                    });
                    location.href = "{{ url_for('manager.gamesets') }}"
                }).catch((err) => {
                    this.$notify.error({
                        title: "登陆失败",
                        message: "用户名或密码错误"
                    })
                });
            }
        }
    });
</script>
{% endblock js %}